package org.ngmj.demo1.serverclientwriter;

import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

@Slf4j
public class Client {
    public static void main(String[] args) {
        try (SocketChannel sc = SocketChannel.open()) {
            sc.connect(new java.net.InetSocketAddress("127.0.0.1", 8080));

            int count = 0;
            while (true) {
                ByteBuffer bb = ByteBuffer.allocate(1024 * 1024);
                int read = sc.read(bb);
                count += read;
                log.info("read {} bytes", count);
                bb.clear();
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
